<?php
class MailController extends Zend_Controller_Action{
	public function indexAction(){
		$form = new Application_Form_Mail();
		$request = $this->getRequest();
		
		if($request->isPost()){
			if($form->isValid($request->getPost())){
				$values = $form->getValues();
				$mapper = new Application_Model_MailMapper();
				$mail = new Application_Model_Mail();
				$mail	->setAuthor($this->_helper->Security->userID())
						->setObject($values['object'])
						->setText($values['text']);
				$mapper->save($mail);
				$this->_helper->redirector('index','index');
			}else{
				$this->view->form = $form;
				$errors = $form->getMessages();
				$messages = array();
				foreach ($errors as $err) {
					foreach($err as $mess){
						$messages[]=$mess;
					}
				}
				$this->view->errors = $messages;
			}
		}else{
			$this->view->form = $form;
		}
	}
}